<?php
namespace app\common\component\user_wallet_vip_log;

use think\Session;

class UserWalletVipLogService {
	public function createV01($data) {
		$userWalletVipLogModel = new UserWalletVipLogModel($data);

    	if($userWalletVipLogModel -> save()) {
    		return [
    			'code' => 0,
    			'message' => '续费钱包日志创建成功',
    			'data' => [
    				'user_wallet_vip_log' => $userWalletVipLogModel
    			]
    		];
    	}

    	return [
			'code' => -1,
			'message' => '续费钱包日志创建失败'
		];
	}
	
	public function createLogV01($type, $active, $price, $is_state, $voucher = '') {
		$data['user_id'] = Session::get('user_id');
		$data['type'] = $type;
		$data['active'] = $active;
		$data['price'] = $price;

		$resultUserWalletVip = (new \app\common\component\user_wallet_vip\UserWalletVipService()) -> getUserWalletVipV01();
		$data['new_price'] = $resultUserWalletVip['data']['user_wallet_vip'] -> price + $price;
		$data['old_price'] = $resultUserWalletVip['data']['user_wallet_vip'] -> price;

		$data['create_time'] = time();
		$data['voucher'] = $voucher;
		$data['is_state'] = $is_state;

		return $this -> createV01($data);
	}
}
?>